package rsj.proxy.bind;

import rsj.proxy.parse.ParamTypeEnum;
import rsj.proxy.parse.ParameterMapping;
import rsj.proxy.parse.SqlParse;
import rsj.proxy.parse.SqlSource;

import java.lang.reflect.Method;
import java.util.List;

/**
 * sql参数解析
 *
 * @author yuanqinglong
 * @since 2021/5/27 16:03
 */
public interface ParamResolveProcessor {


    /**
     * 得到支持的类型
     *
     * @return {@link ParamTypeEnum}
     */
    ParamTypeEnum getSupportType();

    /**
     * 做参数解决
     * sql参数解析
     *
     * @param parameterMapping 参数映射
     * @param method           方法
     * @param args             arg游戏
     * @param sqlSource        sql源
     * @param resolveParamList 参数值列表
     * @throws Exception 异常
     */
    void doParamResolve(SqlSource sqlSource, ParameterMapping parameterMapping, Method method, Object[] args, List<Object> resolveParamList) throws Exception;


    /**
     * 处理like查询
     *
     * @param parameterMapping 参数映射
     * @param arg              参数
     * @return {@link Object}
     */
    default Object handlingLikeQueries(ParameterMapping parameterMapping, Object arg) {
        if (parameterMapping.isLike()) {
            return SqlParse.LIKE + arg + SqlParse.LIKE;
        }
        return arg;
    }

}
